package com.itheima.controller;

import com.itheima.R;
import com.itheima.pojo.SmsHomeNewProduct;
import com.itheima.service.SmsHomeNewProductService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pk
 * @date 2022/10/13/18:00
 */
@RestController
@RequestMapping("home/newProduct")
public class SmsHomeNewProductController {
    @Autowired
    private SmsHomeNewProductService newProductService;

    /**
     * 添加首页新品
     *
     * @param newProduct
     * @return
     */
    @PostMapping("/create")
    public R createNewProduct(@RequestBody SmsHomeNewProduct newProduct) {

        newProductService.createNewProduct(newProduct);

        return R.success("添加首页新品功能执行");
    }

    /**
     * 分页查询新品
     *
     * @param productName
     * @param pageNum
     * @param pageSize
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public R findNewProduct(String productName, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, Integer recommendStatus) {

        PageResult result = newProductService.findNewProduct(productName, pageNum, pageSize, recommendStatus);
        return R.success(result);
    }

    /**
     * 修改首页新品排序
     *
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public R updateSortByid(@PathVariable Long id, Integer sort) {

        newProductService.updateSortByid(id, sort);
        return R.success("修改首页新品排序功能执行");
    }


    /**
     * 批量删除新品
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R deleteNewProduct(Integer[] ids) {

        newProductService.deleteNewProduct(ids);
        return R.success("批量删除新品功能执行");
    }


    /**
     * 批量修改新品
     *
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R updateRecommendStatus(Integer[] ids, Integer recommendStatus) {

        newProductService.updateRecommendStatus(ids, recommendStatus);
        return R.success("批量修改新品状态功能执行");
    }

}
